package com.ccit.common.baiduFace.util;

import com.ccit.common.baiduFace.constant.ImageTypeEnum;
import com.ccit.common.baiduFace.exception.BizException;
import com.ccit.common.baiduFace.pojo.ImageU;
import org.springframework.web.multipart.MultipartFile;

public class PicStringToImgU {

    public static ImageU translate(MultipartFile file) throws Exception {
//        final String[] base64Array = file.split(",");
//        String dataUir = base64Array[0];
//        String picData = base64Array[1];

//        MultipartFile multipartFile = new Base64ToMultipartFile(picData, dataUir);
//        if (multipartFile.isEmpty()) {
//            throw new BizException("上传文件不能为空");
//        }
//        String groupIds = "group1";
        if (file!=null){
            String data = FaceUtil.encodeBase64(file.getBytes());
            ImageU imageU = ImageU.builder().data(data).imageTypeEnum(ImageTypeEnum.BASE64).build();
            return imageU;
        }else {
            throw new BizException("上传文件不能为空");
        }
    }
}
